package com.axjy.web;

import com.axjy.service.PermissionService;
import com.axjy.util.Log;
import com.axjy.web.vo.Node;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by asus on 2018/1/11.
 */

@RestController
@RequestMapping("/sys/permission")
public class PermissionHandler {

    @Resource
    private PermissionService permissionService;

    @GetMapping("/tree")
    public List<Node> search4Tree(Integer roleId){
        return permissionService.search4Tree(roleId);
    }

    @PostMapping("/grant")
    public String grant(Integer roleId,Integer[] mids){
        String msg=null;
        try {
            permissionService.grant4Role(roleId, mids);
            msg="角色授权成功！";
        }catch(RuntimeException ex){
            msg="角色授权失败！";
            Log.logger.debug(msg,ex);
        }
        return msg;
    }




}
